package pers.xx.sbm.service.serviceImpl;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedCaseInsensitiveMap;
import pers.xx.sbm.dao.DyReportCountyDataMapper;
import pers.xx.sbm.service.DyReportCountyDataService;
import pers.xx.sbm.vo.*;

import java.time.LocalDate;
import java.util.*;
import java.util.stream.Collectors;

@Service
public class DyReportCountyDataServiceImpl implements DyReportCountyDataService {

    @Autowired
    private DyReportCountyDataMapper dyReportCountyDataMapper;

    /**
     * 年份-1
     */
    private static int CURRENT_YEAR = LocalDate.now().getYear() - 1;

    /**
     * 总体
     */

    private int numbers = 0;

    /**
     * 小学
     */

    private int xNumbers = 0;
    /**
     * 初中
     */

    private int cNumbers = 0;
    /**
     * 高中
     */

    private int gNumbers = 0;


    @Override
    public int getNumbers(String areaName, String xd) {
        inintNumber(areaName);
        if ("小学".equals(xd)) {
            return xNumbers;
        } else if ("初中".equals(xd)) {
            return cNumbers;
        } else if ("高中".equals(xd)) {
            return gNumbers;
        } else {
            return numbers;
        }
    }

    @Override
    public String getAllSituationTxt(String areaName, String xd) {
        if (StringUtils.isNotBlank(xd)) {
            //区县xd总体得分
            Double score = dyReportCountyDataMapper.queryTotalScore(CURRENT_YEAR, areaName, xd);
            if(null == score) {
                score = 0.0;
            }
            //1 查询该区县学校数量
            int schoolNumbers = dyReportCountyDataMapper.selectSchoolNumbers(areaName, xd);
            //查询今年区县学校列表得分
            List<TotalSampleVo> currentYearSchoolScores = dyReportCountyDataMapper.querySchoolScore(CURRENT_YEAR, areaName, xd, null);

            String result = "经监测，" + areaName + xd + "生品德发展水平平均得分" + score + "，" + levelText(score) + "，全区" + schoolNumbers + "个学校中" + orderSchoolScore(currentYearSchoolScores) + "。具体情况如下表:";
            return result;
        } else {
            //1 查询该区县学校数量
            int schoolNumbers = dyReportCountyDataMapper.selectSchoolNumbers(areaName, "");
            //2 查询区县的总体得分
            Double score = dyReportCountyDataMapper.queryTotalScore(CURRENT_YEAR, areaName, "");
            if(null == score) {
                score = 0.0;
            }
            //查询今年区县学校列表得分
            List<TotalSampleVo> currentYearSchoolScores = dyReportCountyDataMapper.querySchoolScore(CURRENT_YEAR, areaName, "", null);
            //获取学校列表
            List<String> schoolNames = currentYearSchoolScores.stream().map(TotalSampleVo::getName).collect(Collectors.toList());
            //查询去年区县学校列表得分
            List<TotalSampleVo> LastYearSchoolScores = dyReportCountyDataMapper.querySchoolScore(CURRENT_YEAR - 1, areaName, "", schoolNames);
            String result = "经监测，" + areaName + schoolNumbers + "个学校学生思想品德发展水平得分" + score + "，" + levelText(score) + "，" + schoolCompareTotal(areaName, currentYearSchoolScores, LastYearSchoolScores) + "。具体监测情况如下表：";
            return result;
        }


    }


    @Override
    public Map<String, Object> getAllSituationScore(String areaName) {
        Map<String, Object> result = new HashMap<>();
        List<Map<Object, Object>> primary = getAllSituationScoreByXd(areaName, "小学");
        List<Map<Object, Object>> junior = getAllSituationScoreByXd(areaName, "初中");
        List<Map<Object, Object>> senior = getAllSituationScoreByXd(areaName, "高中");
        result.put("primary", primary);
        result.put("junior", junior);
        result.put("senior", senior);
        return result;
    }

    @Override
    public List<Map<String, Object>> getSampleData(String areaName) {
        List<Map<String, Object>> result = new ArrayList<>();
        Map<String, Object> sex = getMapData(areaName, "sex");
        Map<String, Object> dszn = getMapData(areaName, "`6`");
        Map<String, Object> whcd = getMapData(areaName, "`7`");
        Map<String, Object> jzd = getMapData(areaName, "`8`");
        Map<String, Object> bgb = getMapData(areaName, "`9`");
        Map<String, Object> motherStay = getMapData(areaName, "`2`");
        Map<String, Object> fatherStay = getMapData(areaName, "`3`");
        Map<String, Object> nation = getMapData(areaName, "`5`");
        Map<String, Object> cj = getMapData(areaName, "`10`");
        Map<String, Object> stay = getMapData(areaName, "`4`");
        Map<String, Object> schoolType = getMapData(areaName, "`11`");
        Map<String, Object> schoolNature = getMapData(areaName, "`12`");
        Map<String, Object> schoolAddress = getMapData(areaName, "`13`");
        result.add(sex);
        result.add(dszn);
        result.add(whcd);
        result.add(jzd);
        result.add(bgb);
        result.add(motherStay);
        result.add(fatherStay);
        result.add(nation);
        result.add(cj);
        result.add(stay);
        result.add(schoolType);
        result.add(schoolNature);
        result.add(schoolAddress);
        return result;
    }

    @Override
    public List<Map<String, Object>> getAllSituationScoreByAreaAndXd(String areaName, String xd) {
        List<Map<String, Object>> result = new ArrayList<>();

        //查询全市得分
        double scoreTotal = dyReportCountyDataMapper.queryTotalScore(CURRENT_YEAR, "", xd);
        //区县xd总体得分
        Double scoreArea = dyReportCountyDataMapper.queryTotalScore(CURRENT_YEAR, areaName, xd);
        if(null == scoreArea) {
            scoreArea = 0.0;
        }
        //查询今年区县学校列表得分
        List<TotalSampleVo> currentYearSchoolScores = dyReportCountyDataMapper.querySchoolScore(CURRENT_YEAR, areaName, xd, null);

        Map<String, Object> city = new HashMap<>();
        Map<String, Object> area = new HashMap<>();

        city.put("schoolName","全市");
        city.put("score",scoreTotal);
        area.put("schoolName", areaName);
        area.put("score", scoreArea);
        result.add(city);
        result.add(area);

        if (CollectionUtils.isNotEmpty(currentYearSchoolScores)) {
            Collections.sort(currentYearSchoolScores);
            for (TotalSampleVo vo : currentYearSchoolScores) {
                Map<String, Object> data = new HashMap<>();
                data.put("schoolName",vo.getName());
                data.put("score",vo.getValue());
                result.add(data);
            }

        }

        return result;
    }

    @Override
    public Map<String, Object> getDiff(String areaName, String xd, String keyWords) {

        //查询一级指标数量
        List<ScoreSampleVo> scores = dyReportCountyDataMapper.queryIndexScore(keyWords, areaName, xd);
        Set<String> indexNames = scores.stream().map(ScoreSampleVo::getIndexName).collect(Collectors.toSet());
        Set<String> names = scores.stream().map(ScoreSampleVo::getName).collect(Collectors.toSet());
        Map<String, Object> diff = new HashMap<>();
        Map<String, String> desc = new HashMap<>();
        Map<String, List<Double>> data = new HashMap<>();
        for (String indexName : indexNames) {
            desc.put(indexName, getDesc(keyWords, indexName, scores));
        }
        diff.put("desc",desc);
        for (String name : names) {
            List<Double> score = new ArrayList<>();
            for (String indexName : indexNames) {
                score.addAll(scores.stream().filter(vo -> vo.getName().equals(name) && vo.getIndexName().equals(indexName)).map(ScoreSampleVo::getScore).collect(Collectors.toList()));
            }
            if ("`6`".equals(keyWords)) {
                data.put(name.equals("是") ? "独生子女" : "非独生子女", score);
            } else {
                data.put(name, score);
            }
        }
        diff.put("data",data);
        return diff;
    }

    @Override
    public List<Map<String, Object>> getIndexes(String areaName, String xd) {

        List<Map<String, Object>> result = new ArrayList<>();
        //查询区县学段所有一级指标得分
        List<DyIndexScore> indexScores1 = dyReportCountyDataMapper.queryScore1(CURRENT_YEAR, areaName, xd);
        if (CollectionUtils.isEmpty(indexScores1)) {
            return result;
        }
        Set<String> IndexNameS = indexScores1.stream().map(DyIndexScore::getIndexName).collect(Collectors.toSet());
        List<String> parentIndexNameS = new ArrayList<>(IndexNameS);
        //查询区县学段所有学校的二级指标分
        List<DyIndexScore> indexScores2 = dyReportCountyDataMapper.queryScore2(CURRENT_YEAR, areaName, xd, parentIndexNameS);
        for (String name : parentIndexNameS) {
            Map<String, Object> data = new HashMap<>();
            data.put("name", name);
            List<String> tableHead = new ArrayList<>();
            tableHead.add(name);
            Map<String, Object> situation = new LinkedHashMap<>();
            getContent(areaName, name, indexScores1, indexScores2, tableHead, situation);
            Map<String, Object> questions = new LinkedHashMap<>();
            List<String> analysis = new ArrayList<>();
            getQuestion(areaName, name, xd,questions,analysis);
            data.put("situation", situation);
            data.put("questions", questions);
            data.put("analysis", analysis);
            result.add(data);
        }
        return result;
    }

    @Override
    public String getIndexTxt(String areaName) {
        //获取所有二级指标得分
        List<DyIndexScore> scoreList = dyReportCountyDataMapper.queryAllScore2(CURRENT_YEAR, areaName);

        List<DyIndexScore> score_4 = scoreList.stream().filter(vo -> vo.getScore() >= 4).collect(Collectors.toList());
        List<DyIndexScore> score_3_to_4 = scoreList.stream().filter(vo -> vo.getScore() >= 3 && vo.getScore() < 4).collect(Collectors.toList());
        List<DyIndexScore> score_2_to_3 = scoreList.stream().filter(vo -> vo.getScore() >= 2 && vo.getScore() < 3).collect(Collectors.toList());
        List<DyIndexScore> score_0_to_2 = scoreList.stream().filter(vo -> vo.getScore() >= 0 && vo.getScore() < 2).collect(Collectors.toList());
        List<DyIndexScore> score_x = scoreList.stream().filter(vo ->  vo.getXd().equals("小学")).collect(Collectors.toList());
        List<DyIndexScore> score_4_x = scoreList.stream().filter(vo -> vo.getScore() >= 4 && vo.getXd().equals("小学")).collect(Collectors.toList());
        List<DyIndexScore> score_3_to_4_x = scoreList.stream().filter(vo -> vo.getScore() >= 3 && vo.getScore() < 4 && vo.getXd().equals("小学")).collect(Collectors.toList());
        List<DyIndexScore> score_2_to_3_x = scoreList.stream().filter(vo -> vo.getScore() >= 2 && vo.getScore() < 3 && vo.getXd().equals("小学")).collect(Collectors.toList());
        List<DyIndexScore> score_0_to_2_x = scoreList.stream().filter(vo -> vo.getScore() >= 0 && vo.getScore() < 2 && vo.getXd().equals("小学")).collect(Collectors.toList());
        List<DyIndexScore> score_c = scoreList.stream().filter(vo ->  vo.getXd().equals("初中")).collect(Collectors.toList());
        List<DyIndexScore> score_4_c = scoreList.stream().filter(vo -> vo.getScore() >= 4 && vo.getXd().equals("初中")).collect(Collectors.toList());
        List<DyIndexScore> score_3_to_4_c = scoreList.stream().filter(vo -> vo.getScore() >= 3 && vo.getScore() < 4 && vo.getXd().equals("初中")).collect(Collectors.toList());
        List<DyIndexScore> score_2_to_3_c = scoreList.stream().filter(vo -> vo.getScore() >= 2 && vo.getScore() < 3 && vo.getXd().equals("初中")).collect(Collectors.toList());
        List<DyIndexScore> score_0_to_2_c = scoreList.stream().filter(vo -> vo.getScore() >= 0 && vo.getScore() < 2 && vo.getXd().equals("初中")).collect(Collectors.toList());
        List<DyIndexScore> score_g = scoreList.stream().filter(vo ->  vo.getXd().equals("高中")).collect(Collectors.toList());
        List<DyIndexScore> score_4_g = scoreList.stream().filter(vo -> vo.getScore() >= 4 && vo.getXd().equals("高中")).collect(Collectors.toList());
        List<DyIndexScore> score_3_to_4_g = scoreList.stream().filter(vo -> vo.getScore() >= 3 && vo.getScore() < 4 && vo.getXd().equals("高中")).collect(Collectors.toList());
        List<DyIndexScore> score_2_to_3_g = scoreList.stream().filter(vo -> vo.getScore() >= 2 && vo.getScore() < 3 && vo.getXd().equals("高中")).collect(Collectors.toList());
        List<DyIndexScore> score_0_to_2_g = scoreList.stream().filter(vo -> vo.getScore() >= 0 && vo.getScore() < 2 && vo.getXd().equals("高中")).collect(Collectors.toList());

        return "从指标体系来看，在"+ (null == scoreList ? 0 : scoreList.size())+"个监测指标层面中，共有"+ (null == score_4 ? 0 : score_4.size())+"个层面达到4分及以上，"+(null == score_3_to_4 ? 0 : score_3_to_4.size())+"个层面在3-4分之间，"+(null == score_2_to_3 ? 0 : score_2_to_3.size())+"个层面在2-3分之间，"+(null == score_0_to_2 ? 0 : score_0_to_2.size())+"个层面在0-2分之间；"+
                "按学段分析，五年级的"+(null == score_x ? 0 : score_x.size())+"个层面有"+(null == score_4_x ? 0 : score_4_x.size())+"个达到4分及以上，"+(null == score_3_to_4_x ? 0 : score_3_to_4_x.size())+"个3-4分之间，"+(null == score_2_to_3_x ? 0 : score_2_to_3_x.size())+"个在2-3分之间，"+(null == score_0_to_2_x ? 0 : score_0_to_2_x.size())+"个在0-2分之间；" +
                "八年级的"+(null == score_c ? 0 : score_c.size())+"个层面有"+(null == score_4_c ? 0 : score_4_c.size())+"个在4分及以上，"+(null == score_3_to_4_c ? 0 : score_3_to_4_c.size())+"个在3-4 分之间，"+(null == score_2_to_3_c ? 0 : score_2_to_3_c.size())+"个在2-3分之间，"+(null == score_0_to_2_c ? 0 : score_0_to_2_c.size())+"个在0-2分之间；" +
                "高中二年级的"+(null == score_g ? 0 : score_g.size())+"个层面有"+(null == score_4_g ? 0 : score_4_g.size())+"个在4分及以上，"+(null == score_3_to_4_g ? 0 : score_3_to_4_g.size())+"个层面在3-4 分之间，"+(null == score_2_to_3_g ? 0 : score_2_to_3_g.size())+"个在2-3分之间，"+(null == score_0_to_2_g ? 0 : score_0_to_2_g.size())+"个在0-2分之间。" +
                "相对于2020年，：";
    }


    private void getContent(String areaName, String indexName1, List<DyIndexScore> indexScores1, List<DyIndexScore> indexScores2, List<String> tableHead, Map<String, Object> situation) {
        if (StringUtils.isBlank(indexName1)) {
            return;
        }
        Set<String> indexNames2 = indexScores2.stream().filter(vo -> vo.getParentIndexName().equals(indexName1)).map(DyIndexScore::getIndexName).collect(Collectors.toSet());
        List<DyIndexScore> collect = indexScores1.stream().filter(vo -> vo.getIndexName().equals(indexName1) && vo.getAreaName().equals(areaName) && vo.getSchoolName().equals("-1")).collect(Collectors.toList());
        double index1Score = 0.0;
        if(CollectionUtils.isNotEmpty(collect)) {
            index1Score = collect.get(0).getScore();
        }
        Iterator<String> iterator = indexNames2.iterator();
        String content = "监测主要是从学生";
        int index = 0;
        while (iterator.hasNext()) {
            index += 1;
            content += iterator.next() + "、";
        }
        content = content.substring(0, content.length() - 1) + index + "个层面测查学生的" + indexName1 + "。在平均值1-5分的分布中，全区学生在" + indexName1 + "方面的平均得分为" + index1Score + "。其中，";
        List<DyIndexScore> index2Scores = indexScores2.stream().filter(vo -> vo.getAreaName().equals(areaName) && vo.getParentIndexName().equals(indexName1) && vo.getSchoolName().equals("-1")).collect(Collectors.toList());
        for (DyIndexScore score : index2Scores) {
            tableHead.add(score.getIndexName());
            content += "在" + score.getIndexName() + "层面的平均得分为" + score.getScore() + "。";
        }
        content += "具体情况如下表：";
        situation.put("content", content);

        situation.put("tableHead", tableHead);
        Map<String,List<Double>> data = new LinkedHashMap<>();
        //处理市
        for (DyIndexScore score1 : indexScores1) {
            List<Double> scoreList = new ArrayList<>();
            if (score1.getIndexName().equals(indexName1) && score1.getAreaName().equals("全市") && score1.getSchoolName().equals("-1")) {
                scoreList.add(score1.getScore());
                for (DyIndexScore score2 : indexScores2) {
                    if (score2.getAreaName().equals("全市") && score2.getParentIndexName().equals(indexName1) && score1.getSchoolName().equals("-1")) {
                        scoreList.add(score2.getScore());
                    }
                }
                data.put( "全市" , scoreList);
            }
        }
        //处理区县
        for (DyIndexScore score1 : indexScores1) {
            List<Double> scoreList = new ArrayList<>();
            if (score1.getIndexName().equals(indexName1) && score1.getAreaName().equals(areaName) && score1.getSchoolName().equals("-1")) {
                scoreList.add(score1.getScore());
                for (DyIndexScore score2 : indexScores2) {
                    if (score2.getAreaName().equals(areaName) && score2.getParentIndexName().equals(indexName1) && score2.getSchoolName().equals("-1")) {
                        scoreList.add(score2.getScore());
                    }
                }
                data.put(areaName , scoreList);
            }
        }
        //处理学校
        for (DyIndexScore score1 : indexScores1) {
            List<Double> scoreList = new ArrayList<>();
            if (score1.getIndexName().equals(indexName1) && score1.getAreaName().equals(areaName)&& !score1.getSchoolName().equals("-1")) {
                scoreList.add(score1.getScore());
                for (DyIndexScore score2 : indexScores2) {
                    if (score2.getAreaName().equals(areaName) && score2.getParentIndexName().equals(indexName1) &&  score1.getSchoolName().equals(score2.getSchoolName())) {
                        scoreList.add(score2.getScore());
                    }
                }
                data.put(score1.getSchoolName(), scoreList);
            }
        }
        situation.put("data", data);
}

    private void getQuestion(String areaName, String indexName,String xd,Map<String, Object> questions,List<String> analysis) {
        List<DyQuestion> dyQuestions = dyReportCountyDataMapper.queryQuestionScore(CURRENT_YEAR, areaName, indexName, xd);
        if(CollectionUtils.isNotEmpty(dyQuestions)){
            for(DyQuestion question:dyQuestions) {
                List<Object> data = new ArrayList<>();
                data.add(question.getQuestionType());
                data.add(question.getIndex2());
                data.add(question.getScore());
                data.add(question.getCorrectProportion());
                data.add(question.getErrorProportion());
                questions.put(question.getStem(),data);
            }


            Set<String> index2Names = dyQuestions.stream().map(DyQuestion::getIndex2).collect(Collectors.toSet());

            for(String index2Name : index2Names) {
                //todo 未完成
                String desc = "在“"+index2Name+"”问题上，";
                analysis.add(desc);
            }
        }

    }

    private String getDesc(String keyWords, String name, List<ScoreSampleVo> scores) {
        String txt = "在" + name + "指标上，";
        if ("`8`".equals(keyWords)) {
            List<ScoreSampleVo> collect = scores.stream().filter(vo -> vo.getIndexName().equals(name)).collect(Collectors.toList());
            Collections.sort(collect);
            txt += "居住在" + collect.get(0).getName() + "的学生的得分最高（" + collect.get(0).getScore() + "），居住在" + collect.get(1).getName() + "学生得分次之（" + collect.get(1).getScore() + "），居住在" + collect.get(2).getName() + "学生得分最低（" + collect.get(2).getScore() + "）。";
        }
        if ("sex".equals(keyWords)) {
            List<ScoreSampleVo> collect = scores.stream().filter(vo -> vo.getIndexName().equals(name)).collect(Collectors.toList());
            Collections.sort(collect);
            txt += "男生和女生学生得分差别较小。总体而言，" + collect.get(0).getName() + "生（" + collect.get(0).getScore() + "）比" + collect.get(1).getName() + "生（" + collect.get(1).getScore() + "）的规则意识认知强一些。";
        }
        if ("`6`".equals(keyWords)) {
            List<ScoreSampleVo> collect = scores.stream().filter(vo -> vo.getIndexName().equals(name)).collect(Collectors.toList());
            Collections.sort(collect);
            txt += "独生子女和非独生子女的学生得分差别较小。总体而言，" + (collect.get(0).getName().equals("是") ? "独生子女" : "非独生子女") + "（" + collect.get(0).getScore() + "）比" + (collect.get(1).getName().equals("是") ? "独生子女" : "非独生子女") + "（" + collect.get(1).getScore() + "）的珍爱生命认知强一些。";
        }
        if ("`10`".equals(keyWords)) {
            List<ScoreSampleVo> collect = scores.stream().filter(vo -> vo.getIndexName().equals(name)).collect(Collectors.toList());
            Collections.sort(collect);
            txt += "成绩" + collect.get(0).getName() + "的学生的得分最高为" + collect.get(0).getScore() + "，" + collect.get(1).getName() + "的学生得分为" + collect.get(1).getScore() + "，" + collect.get(2).getName() + "的学生得分为" + collect.get(2).getScore() + "，" + collect.get(3).getName() + "的学生得分为" + collect.get(3).getScore() + "，而" + collect.get(4).getName() + "的学生得分最低为" + collect.get(4).getScore() + "。";
        }
        return txt;
    }

    private Map<String, Object> getMapData(String areaName, String keyWords) {
        Map<String, Object> result = new HashMap<>();

        String txt = "";
        Map<String, List<Integer>> data = new LinkedHashMap<>();
        if ("sex".equals(keyWords)) {
            List<NumberSampleVo> numbers = dyReportCountyDataMapper.queryNumber(keyWords, areaName);
            int total = 0;
            int total1 = 0; //男
            int total2 = 0; //女
            for (NumberSampleVo vo : numbers) {
                if (vo.getName().equals("男")) {
                    total1 += vo.getNumber();
                }
                if (vo.getName().equals("女")) {
                    total2 += vo.getNumber();
                }
                total += vo.getNumber();
            }
            List<Integer> sexNumber1 = numbers.stream().filter(vo -> vo.getName().equals("男")).map(NumberSampleVo::getNumber).collect(Collectors.toList());
            List<Integer> sexNumber2 = numbers.stream().filter(vo -> vo.getName().equals("女")).map(NumberSampleVo::getNumber).collect(Collectors.toList());
            data.put("男", sexNumber1);
            data.put("女", sexNumber2);
            txt = "在本次测试中，" + areaName + "男生" + total1 + "人，占比" + getPercentNo(total1, total) + "%，女生" + total2 + "人，占比" + getPercentNo(total2, total) + "%，其中五年级男生" + getNumber(numbers, "小学", "男") + "人，女生" + getNumber(numbers, "小学", "女") + "人，初二男生" + getNumber(numbers, "初中", "男") + "人，女生" + getNumber(numbers, "初中", "女") + "人，高二男生" + getNumber(numbers, "高中", "男") + "人，女生" + getNumber(numbers, "高中", "女") + "人，具体情况见下图:";
        }
        if ("`6`".equals(keyWords)) {
            List<NumberSampleVo> numbers = dyReportCountyDataMapper.queryNumber(keyWords, areaName);
            int total = 0;
            int total1 = 0; //是
            int total2 = 0; //否
            for (NumberSampleVo vo : numbers) {
                if (vo.getName().equals("是")) {
                    total1 += vo.getNumber();
                }
                if (vo.getName().equals("否")) {
                    total2 += vo.getNumber();
                }
                total += vo.getNumber();
            }
            List<Integer> number1 = numbers.stream().filter(vo -> vo.getName().equals("是")).map(NumberSampleVo::getNumber).collect(Collectors.toList());
            List<Integer> number2 = numbers.stream().filter(vo -> vo.getName().equals("否")).map(NumberSampleVo::getNumber).collect(Collectors.toList());
            data.put("独生子女", number1);
            data.put("非独生子女", number2);
            txt = "在本次测试中，" + areaName + "独生子女" + total1 + "，占比" + getPercentNo(total1, total) + "%，非独生子女" + total2 + "人，占比" + getPercentNo(total2, total) + "%，其中五年级独生子女" + getNumber(numbers, "小学", "是") + "人，非独生子女" + getNumber(numbers, "小学", "否") + "人，初二独生子女" + getNumber(numbers, "初中", "是") + "人，非独生子女" + getNumber(numbers, "初中", "否") + "人，高二独生子女" + getNumber(numbers, "高中", "是") + "人，非独生子女" + getNumber(numbers, "高中", "否") + "人，具体情况见下图:";
        }
        if ("`7`".equals(keyWords)) {
            List<NumberSampleVo> numbers = dyReportCountyDataMapper.queryNumber(keyWords, areaName);
            int total = 0;
            int total1 = 0; //大学
            int total2 = 0; //研究生
            int total3 = 0; //没上过学
            for (NumberSampleVo vo : numbers) {
                if (vo.getName().equals("大学（大专、高职、本科）")) {
                    total1 += vo.getNumber();
                }
                if (vo.getName().equals("研究生（硕士、博士）")) {
                    total2 += vo.getNumber();
                }
                if (vo.getName().equals("没上过学")) {
                    total3 += vo.getNumber();
                }
                total += vo.getNumber();
            }
            List<Integer> number1 = numbers.stream().filter(vo -> vo.getName().equals("没上过学")).map(NumberSampleVo::getNumber).collect(Collectors.toList());
            List<Integer> number2 = numbers.stream().filter(vo -> vo.getName().equals("小学")).map(NumberSampleVo::getNumber).collect(Collectors.toList());
            List<Integer> number3 = numbers.stream().filter(vo -> vo.getName().equals("初中")).map(NumberSampleVo::getNumber).collect(Collectors.toList());
            List<Integer> number4 = numbers.stream().filter(vo -> vo.getName().equals("高中（中专、中技、职高）")).map(NumberSampleVo::getNumber).collect(Collectors.toList());
            List<Integer> number5 = numbers.stream().filter(vo -> vo.getName().equals("大学（大专、高职、本科）")).map(NumberSampleVo::getNumber).collect(Collectors.toList());
            List<Integer> number6 = numbers.stream().filter(vo -> vo.getName().equals("研究生（硕士、博士）")).map(NumberSampleVo::getNumber).collect(Collectors.toList());
            data.put("没上过学", number1);
            data.put("小学", number2);
            data.put("初中", number3);
            data.put("高中", number4);
            data.put("大学", number5);
            data.put("研究生", number6);

            txt = "从本次监测数据结果看，学生父母文化程度为大学的占比为" + getPercentNo(total1, total) + "%，另有部分学生父母的文化程度达到了研究生水平，占比为" + getPercentNo(total2, total) + "%，少量学生父母未接受过正规教育，占比为" + getPercentNo(total3, total) + "%。各年级具体情况见下图:";
        }
        if ("`8`".equals(keyWords)) {
            List<NumberSampleVo> numbers = dyReportCountyDataMapper.queryNumber(keyWords, areaName);
            int total = 0;
            int total1 = 0; //城市
            int total2 = 0; //县镇
            int total3 = 0; //农村
            for (NumberSampleVo vo : numbers) {
                if (vo.getName().equals("城市")) {
                    total1 += vo.getNumber();
                }
                if (vo.getName().equals("县镇")) {
                    total2 += vo.getNumber();
                }
                if (vo.getName().equals("农村")) {
                    total3 += vo.getNumber();
                }
                total += vo.getNumber();
            }
            List<Integer> number1 = numbers.stream().filter(vo -> vo.getName().equals("城市")).map(NumberSampleVo::getNumber).collect(Collectors.toList());
            List<Integer> number2 = numbers.stream().filter(vo -> vo.getName().equals("县镇")).map(NumberSampleVo::getNumber).collect(Collectors.toList());
            List<Integer> number3 = numbers.stream().filter(vo -> vo.getName().equals("农村")).map(NumberSampleVo::getNumber).collect(Collectors.toList());
            data.put("城市", number1);
            data.put("县镇", number2);
            data.put("农村", number3);

            txt = "从本次监测数据结果看，居住在城市的学生人数比例最多，为" + getPercentNo(total1, total) + "%。居住在县镇的学生人数比例次之，为" + getPercentNo(total2, total) + "%。居住在农村的学生人数比例最少，为" + getPercentNo(total3, total) + "%。具体情况见下图:";
        }

        if ("`9`".equals(keyWords)) {
            List<NumberSampleVo> numbers = dyReportCountyDataMapper.queryNumber(keyWords, areaName);
            int total = 0;
            int total1 = 0; //班干部
            int total2 = 0; //非班干部
            for (NumberSampleVo vo : numbers) {
                if (vo.getName().equals("是")) {
                    total1 += vo.getNumber();
                }
                if (vo.getName().equals("否")) {
                    total2 += vo.getNumber();
                }
                total += vo.getNumber();
            }
            List<Integer> number1 = numbers.stream().filter(vo -> vo.getName().equals("是")).map(NumberSampleVo::getNumber).collect(Collectors.toList());
            List<Integer> number2 = numbers.stream().filter(vo -> vo.getName().equals("否")).map(NumberSampleVo::getNumber).collect(Collectors.toList());
            data.put("班干部", number1);
            data.put("非班干部", number2);

            txt = "在本次测试中，" + areaName + "学生是班干部占比" + getPercentNo(total1, total) + "%，不是班干部占比" + getPercentNo(total2, total) + "%，其中五年级班干部" + getNumber(numbers, "小学", "是") + "人，非班干部" + getNumber(numbers, "小学", "否") + "人，初二班干部" + getNumber(numbers, "初中", "是") + "人，非班干部" + getNumber(numbers, "初中", "否") + "人，高二班干部" + getNumber(numbers, "高中", "是") + "人，非班干部" + getNumber(numbers, "高中", "否") + "人，具体情况见下图:";
        }

        if ("`2`".equals(keyWords)) {
            List<NumberSampleVo> numbers = dyReportCountyDataMapper.queryNumber(keyWords, areaName);
            int total = 0;
            int total1 = 0; //不足 6个月
            int total2 = 0; //6-8个月
            int total3 = 0; //9-11个月
            int total4 = 0; //12个月都在
            for (NumberSampleVo vo : numbers) {
                if (vo.getName().equals("不足 6个月")) {
                    total1 += vo.getNumber();
                }
                if (vo.getName().equals("6-8个月")) {
                    total2 += vo.getNumber();
                }
                if (vo.getName().equals("9-11个月")) {
                    total3 += vo.getNumber();
                }
                if (vo.getName().equals("12个月都在")) {
                    total4 += vo.getNumber();
                }
                total += vo.getNumber();
            }
            List<Integer> number1 = numbers.stream().filter(vo -> vo.getName().equals("不足 6个月")).map(NumberSampleVo::getNumber).collect(Collectors.toList());
            List<Integer> number2 = numbers.stream().filter(vo -> vo.getName().equals("6-8个月")).map(NumberSampleVo::getNumber).collect(Collectors.toList());
            List<Integer> number3 = numbers.stream().filter(vo -> vo.getName().equals("9-11个月")).map(NumberSampleVo::getNumber).collect(Collectors.toList());
            List<Integer> number4 = numbers.stream().filter(vo -> vo.getName().equals("12个月都在")).map(NumberSampleVo::getNumber).collect(Collectors.toList());
            data.put("12个月都在", number4);
            data.put("9-11个月", number3);
            data.put("6-8个月", number2);
            data.put("不足6个月", number1);

            txt = "从本次监测数据结果看，妈妈12个月都在家的占比为" + getPercentNo(total4, total) + "%，9-11个月的占比为" + getPercentNo(total3, total) + "%，6-8个月的占比为" + getPercentNo(total2, total) + "%，不足6个月的占比为" + getPercentNo(total1, total) + "%。各年级具体情况见下图:";
        }

        if ("`3`".equals(keyWords)) {
            List<NumberSampleVo> numbers = dyReportCountyDataMapper.queryNumber(keyWords, areaName);
            int total = 0;
            int total1 = 0; //不足6个月
            int total2 = 0; //6-8个月
            int total3 = 0; //9-11个月
            int total4 = 0; //12个月都在
            for (NumberSampleVo vo : numbers) {
                if (vo.getName().equals("不足 6个月")) {
                    total1 += vo.getNumber();
                }
                if (vo.getName().equals("6-8个月")) {
                    total2 += vo.getNumber();
                }
                if (vo.getName().equals("9-11个月")) {
                    total3 += vo.getNumber();
                }
                if (vo.getName().equals("12个月都在")) {
                    total4 += vo.getNumber();
                }
                total += vo.getNumber();
            }
            List<Integer> number1 = numbers.stream().filter(vo -> vo.getName().equals("不足 6个月")).map(NumberSampleVo::getNumber).collect(Collectors.toList());
            List<Integer> number2 = numbers.stream().filter(vo -> vo.getName().equals("6-8个月")).map(NumberSampleVo::getNumber).collect(Collectors.toList());
            List<Integer> number3 = numbers.stream().filter(vo -> vo.getName().equals("9-11个月")).map(NumberSampleVo::getNumber).collect(Collectors.toList());
            List<Integer> number4 = numbers.stream().filter(vo -> vo.getName().equals("12个月都在")).map(NumberSampleVo::getNumber).collect(Collectors.toList());
            data.put("12个月都在", number4);
            data.put("9-11个月", number3);
            data.put("6-8个月", number2);
            data.put("不足6个月", number1);

            txt = "从本次监测数据结果看，爸爸12个月都在家的占比为" + getPercentNo(total4, total) + "%，9-11个月的占比为" + getPercentNo(total3, total) + "%，6-8个月的占比为" + getPercentNo(total2, total) + "%，不足6个月的占比为" + getPercentNo(total1, total) + "%。各年级具体情况见下图:";
        }

        if ("`5`".equals(keyWords)) {
            List<NumberSampleVo> numbers = dyReportCountyDataMapper.queryNumber(keyWords, areaName);
            int total = 0;
            int total1 = 0; //汉族
            int total2 = 0; //少数民族
            for (NumberSampleVo vo : numbers) {
                if (vo.getName().equals("汉族")) {
                    total1 += vo.getNumber();
                }
                if (vo.getName().equals("少数民族")) {
                    total2 += vo.getNumber();
                }
                total += vo.getNumber();
            }
            List<Integer> number1 = numbers.stream().filter(vo -> vo.getName().equals("汉族")).map(NumberSampleVo::getNumber).collect(Collectors.toList());
            List<Integer> number2 = numbers.stream().filter(vo -> vo.getName().equals("少数民族")).map(NumberSampleVo::getNumber).collect(Collectors.toList());
            data.put("汉族", number1);
            data.put("少数民族", number2);

            txt = "在本次测试中，" + areaName + "汉族占比" + getPercentNo(total1, total) + "%，少数民族占比" + getPercentNo(total2, total) + "%，其中汉族" + total1 + "人，少数民族" + total2 + "人，具体情况见下图:";
        }

        if ("`10`".equals(keyWords)) {
            List<NumberSampleVo> numbers = dyReportCountyDataMapper.queryNumber(keyWords, areaName);
            int total = 0;
            int total1 = 0; //名列前茅
            int total2 = 0; //中等偏上
            int total3 = 0; //中等水平
            int total4 = 0; //中等偏下
            int total5 = 0; //偏下水平
            for (NumberSampleVo vo : numbers) {
                if (vo.getName().equals("名列前茅")) {
                    total1 += vo.getNumber();
                }
                if (vo.getName().equals("中等偏上")) {
                    total2 += vo.getNumber();
                }
                if (vo.getName().equals("中等水平")) {
                    total3 += vo.getNumber();
                }
                if (vo.getName().equals("中等偏下")) {
                    total4 += vo.getNumber();
                }
                if (vo.getName().equals("偏下水平")) {
                    total5 += vo.getNumber();
                }
                total += vo.getNumber();
            }
            List<Integer> number1 = numbers.stream().filter(vo -> vo.getName().equals("名列前茅")).map(NumberSampleVo::getNumber).collect(Collectors.toList());
            List<Integer> number2 = numbers.stream().filter(vo -> vo.getName().equals("中等偏上")).map(NumberSampleVo::getNumber).collect(Collectors.toList());
            List<Integer> number3 = numbers.stream().filter(vo -> vo.getName().equals("中等水平")).map(NumberSampleVo::getNumber).collect(Collectors.toList());
            List<Integer> number4 = numbers.stream().filter(vo -> vo.getName().equals("中等偏下")).map(NumberSampleVo::getNumber).collect(Collectors.toList());
            List<Integer> number5 = numbers.stream().filter(vo -> vo.getName().equals("偏下水平")).map(NumberSampleVo::getNumber).collect(Collectors.toList());
            data.put("名列前茅", number1);
            data.put("中等偏上", number2);
            data.put("中等水平", number3);
            data.put("中等偏下", number4);
            data.put("偏下水平", number5);

            txt = "从本次监测数据结果看，学生认为自己成绩在班里名列前茅的人数占比为" + getPercentNo(total1, total) + "%，学生认为自己成绩在班里中等偏上的人数占比为" + getPercentNo(total2, total) + "%，学生认为自己成绩在班里中等的人数占比为" + getPercentNo(total3, total) + "%，学生认为自己成绩在班里中等偏下的人数占比为" + getPercentNo(total4, total) + "%，学生认为自己成绩在班里偏下的人数占比为" + getPercentNo(total5, total) + "%。各年级具体情况见下图:";
        }

        if ("`4`".equals(keyWords)) {
            List<NumberSampleVo> numbers = dyReportCountyDataMapper.queryNumber(keyWords, areaName);
            int total = 0;
            int total1 = 0; //住在家里
            int total2 = 0; //在学校寄宿
            int total3 = 0; //住在其他亲戚或朋友家
            for (NumberSampleVo vo : numbers) {
                if (vo.getName().equals("住在家里")) {
                    total1 += vo.getNumber();
                }
                if (vo.getName().equals("在学校寄宿")) {
                    total2 += vo.getNumber();
                }
                if (vo.getName().equals("住在其他亲戚或朋友家")) {
                    total3 += vo.getNumber();
                }
                total += vo.getNumber();
            }
            List<Integer> number1 = numbers.stream().filter(vo -> vo.getName().equals("住在家里")).map(NumberSampleVo::getNumber).collect(Collectors.toList());
            List<Integer> number2 = numbers.stream().filter(vo -> vo.getName().equals("在学校寄宿")).map(NumberSampleVo::getNumber).collect(Collectors.toList());
            List<Integer> number3 = numbers.stream().filter(vo -> vo.getName().equals("住在其他亲戚或朋友家")).map(NumberSampleVo::getNumber).collect(Collectors.toList());
            data.put("住在家里", number1);
            data.put("在学校寄宿", number2);
            data.put("住在其他亲戚或朋友家", number3);

            txt = "从本次监测数据结果看，" + areaName + "学生住宿状况中住在家里占比为" + getPercentNo(total1, total) + "%，在学校寄宿占比为" + getPercentNo(total2, total) + "%，住在其他亲戚或朋友家的学生占比为" + getPercentNo(total3, total) + "%。具体情况见下图:";
        }

        if ("`11`".equals(keyWords)) {
            List<NumberSampleVo> numbers = dyReportCountyDataMapper.queryNumber("LEFT(`11`,4)", areaName);
            int total = 0;
            int total1 = 0; //一类学校
            int total2 = 0; //二类学校
            int total3 = 0; //三类学校
            int total4 = 0; //教学点
            for (NumberSampleVo vo : numbers) {
                if (vo.getName().equals("一类学校")) {
                    total1 += vo.getNumber();
                }
                if (vo.getName().equals("二类学校")) {
                    total2 += vo.getNumber();
                }
                if (vo.getName().equals("三类学校")) {
                    total3 += vo.getNumber();
                }
                if (vo.getName().equals("教学点")) {
                    total4 += vo.getNumber();
                }
                total += vo.getNumber();
            }
            List<Integer> number1 = numbers.stream().filter(vo -> vo.getName().equals("一类学校")).map(NumberSampleVo::getNumber).collect(Collectors.toList());
            List<Integer> number2 = numbers.stream().filter(vo -> vo.getName().equals("二类学校")).map(NumberSampleVo::getNumber).collect(Collectors.toList());
            List<Integer> number3 = numbers.stream().filter(vo -> vo.getName().equals("三类学校")).map(NumberSampleVo::getNumber).collect(Collectors.toList());
            List<Integer> number4 = numbers.stream().filter(vo -> vo.getName().equals("教学点")).map(NumberSampleVo::getNumber).collect(Collectors.toList());
            data.put("一类学校", number1);
            data.put("二类学校", number2);
            data.put("三类学校", number3);
            data.put("教学点", number4);

            txt = "从本次监测数据结果看，" + areaName + "学校中一类学校占比" + getPercentNo(total1, total) + "%，二类学校占比" + getPercentNo(total2, total) + "%，三类学校占比" + getPercentNo(total3, total) + "%，教学点占比" + getPercentNo(total4, total) + "%。具体情况见下图:";
        }

        if ("`12`".equals(keyWords)) {
            List<NumberSampleVo> numbers = dyReportCountyDataMapper.queryNumber(keyWords, areaName);
            int total = 0;
            int total1 = 0; //公办学校
            int total2 = 0; //民办学校
            int total3 = 0; //合作办学
            for (NumberSampleVo vo : numbers) {
                if (vo.getName().equals("公办学校")) {
                    total1 += vo.getNumber();
                }
                if (vo.getName().equals("民办学校")) {
                    total2 += vo.getNumber();
                }
                if (vo.getName().equals("合作办学")) {
                    total3 += vo.getNumber();
                }
                total += vo.getNumber();
            }
            List<Integer> number1 = numbers.stream().filter(vo -> vo.getName().equals("公办学校")).map(NumberSampleVo::getNumber).collect(Collectors.toList());
            List<Integer> number2 = numbers.stream().filter(vo -> vo.getName().equals("民办学校")).map(NumberSampleVo::getNumber).collect(Collectors.toList());
            List<Integer> number3 = numbers.stream().filter(vo -> vo.getName().equals("合作办学")).map(NumberSampleVo::getNumber).collect(Collectors.toList());
            data.put("公办学校", number1);
            data.put("民办学校", number2);
            data.put("合作办学", number3);

            txt = "从本次监测数据结果看，" + areaName + "学校中公办学校占比" + getPercentNo(total1, total) + "%，民办学校占比" + getPercentNo(total2, total) + "%，合作办学占比" + getPercentNo(total3, total) + "%。具体情况见下图:";
        }

        if ("`13`".equals(keyWords)) {
            List<NumberSampleVo> numbers = dyReportCountyDataMapper.queryNumber(keyWords, areaName);
            int total = 0;
            int total1 = 0; //城镇
            int total2 = 0; //乡村
            for (NumberSampleVo vo : numbers) {
                if (vo.getName().equals("城镇")) {
                    total1 += vo.getNumber();
                }
                if (vo.getName().equals("乡村")) {
                    total2 += vo.getNumber();
                }
                total += vo.getNumber();
            }
            List<Integer> number1 = numbers.stream().filter(vo -> vo.getName().equals("城镇")).map(NumberSampleVo::getNumber).collect(Collectors.toList());
            List<Integer> number2 = numbers.stream().filter(vo -> vo.getName().equals("乡村")).map(NumberSampleVo::getNumber).collect(Collectors.toList());
            data.put("城镇", number1);
            data.put("乡村", number2);

            txt = "从本次监测数据结果看，"+areaName+"学校中位于城镇的学校占比" + getPercentNo(total1, total) + "%，位于乡村的学校占比" + getPercentNo(total2, total) + "%。具体情况见下图:";
        }

        result.put("txt", txt);
        result.put("data", data);

        return result;
    }

    private int getNumber(List<NumberSampleVo> numbers, String xd, String keyWords) {
        if (CollectionUtils.isEmpty(numbers)) {
            return 0;
        }
        List<NumberSampleVo> collect = numbers.stream().filter(vo -> vo.getXd().equals(xd) && vo.getName().equals(keyWords)).collect(Collectors.toList());
        if (CollectionUtils.isNotEmpty(collect)) {
            return collect.get(0).getNumber();
        } else {
            return 0;
        }
    }

    private Double getPercentNo(int a, int b) {
        if (a == 0 || b == 0) {
            return 0.0;
        }
        return Double.parseDouble(String.format("%.2f", (float) a / (float) b * 100));
    }

    private List<Map<Object, Object>> getAllSituationScoreByXd(String areaName, String xd) {
        List<Map<Object, Object>> result = new ArrayList<>();
        //查询今年区县学校列表得分
        List<TotalSampleVo> SchoolScoresX1 = dyReportCountyDataMapper.querySchoolScore(CURRENT_YEAR, areaName, xd, new ArrayList<>());
        //获取学校列表
        List<String> schoolNames = SchoolScoresX1.stream().map(TotalSampleVo::getName).collect(Collectors.toList());
        //查询去年区县学校列表得分
        List<TotalSampleVo> SchoolScoresX2 = dyReportCountyDataMapper.querySchoolScore(CURRENT_YEAR - 1, areaName, xd, schoolNames);
        //查询前年区县学校列表得分
        List<TotalSampleVo> SchoolScoresX3 = dyReportCountyDataMapper.querySchoolScore(CURRENT_YEAR - 2, areaName, xd, schoolNames);
        for (String name : schoolNames) {
            Map<Object, Object> data = new HashMap<>();
            data.put("schoolName", name);
            data.put(CURRENT_YEAR, "——");
            data.put(CURRENT_YEAR - 1, "——");
            data.put(CURRENT_YEAR - 2, "——");
            double score1 = 0.0;
            double score2 = 0.0;
            for (TotalSampleVo vo : SchoolScoresX1) {
                if (vo.getName().equals(name)) {
                    data.put(CURRENT_YEAR, vo.getValue());
                    score1 = Double.parseDouble(vo.getValue().toString());
                }
            }
            if (CollectionUtils.isNotEmpty(SchoolScoresX2)) {
                for (TotalSampleVo vo : SchoolScoresX2) {
                    if (vo.getName().equals(name)) {
                        data.put(CURRENT_YEAR - 1, vo.getValue());
                        score2 = Double.parseDouble(vo.getValue().toString());
                    }
                }
            }
            if (CollectionUtils.isNotEmpty(SchoolScoresX3)) {
                for (TotalSampleVo vo : SchoolScoresX3) {
                    if (vo.getName().equals(name)) {
                        data.put(CURRENT_YEAR - 2, vo.getValue());
                    }
                }
            }
            if (score2 == 0) {
                data.put("diff", "——");
            } else {
                data.put("diff", String.format("%.2f", (score1 - score2)));
            }
            result.add(data);
        }
        return result;
    }

    private String schoolCompareTotal(String areaName, List<TotalSampleVo> currentYearSchoolScores, List<TotalSampleVo> lastYearSchoolScores) {
        String result = "其中，";
        if (CollectionUtils.isEmpty(currentYearSchoolScores)) {
            return result;
        }
        if (CollectionUtils.isEmpty(lastYearSchoolScores)) {
            return result + "较" + (CURRENT_YEAR - 1) + "全部上升";
        }
        List<String> up = new ArrayList<>();
        List<String> down = new ArrayList<>();
        List<String> keep = new ArrayList<>();

        //组装数据
        for (TotalSampleVo vo1 : currentYearSchoolScores) {
            String schoolName1 = vo1.getName();
            double score1 = Double.parseDouble(vo1.getValue().toString());
            for (TotalSampleVo vo2 : lastYearSchoolScores) {
                String schoolName2 = vo2.getName();
                if (schoolName1.equals(schoolName2)) {
                    double score2 = Double.parseDouble(vo2.getValue().toString());
                    if (score1 > score2) {
                        up.add(schoolName1);
                    } else if (score1 < score2) {
                        down.add(schoolName1);
                    } else {
                        keep.add(schoolName1);
                    }
                }
            }

        }

        if (CollectionUtils.isNotEmpty(down)) {
            for (String name : down) {
                result += name + "、";
            }
        }
        result = result.substring(0, result.length() - 1) + "较" + (CURRENT_YEAR - 1) + "年有所下降之外，其余学校都较" + (CURRENT_YEAR - 1) + "年有不同程度的上升";
        return result;
    }

    private void inintNumber(String areaName) {
        List<Integer> numbersList = dyReportCountyDataMapper.selectNumbers(areaName);
        if (CollectionUtils.isNotEmpty(numbersList)) {
            xNumbers = numbersList.get(0);
            cNumbers = numbersList.get(1);
            gNumbers = numbersList.get(2);
            numbers = xNumbers + cNumbers + gNumbers;
        }
    }


    private String levelText(double currentYearValue) {
        String compareTxt = "";
        if (currentYearValue >= 80) {
            compareTxt = "总体上处于高水平，非常符合教育预期";
        } else if (currentYearValue >= 60 && currentYearValue < 80) {
            compareTxt = "总体上处于中上水平，基本达到教育预期";
        } else {
            compareTxt = "总体上处于中下水平，未达到教育预期";
        }
        return compareTxt;
    }

    private String orderSchoolScore(List<TotalSampleVo> currentYearSchoolScores) {
        if (CollectionUtils.isEmpty(currentYearSchoolScores)) {
            return "";
        }
        Collections.sort(currentYearSchoolScores);
        List<TotalSampleVo> hight = new ArrayList<>();
        List<TotalSampleVo> low = new ArrayList<>();
        if (currentYearSchoolScores.size() > 15) {
            hight = currentYearSchoolScores.subList(0, 9);
            low = currentYearSchoolScores.subList(currentYearSchoolScores.size() - 3, currentYearSchoolScores.size());
        } else if(currentYearSchoolScores.size() < 3) {
            hight = currentYearSchoolScores.subList(0, 1);
            low = currentYearSchoolScores.subList(currentYearSchoolScores.size() - 1, currentYearSchoolScores.size());

        }else {
            hight = currentYearSchoolScores.subList(0, 3);
            low = currentYearSchoolScores.subList(currentYearSchoolScores.size() - 3, currentYearSchoolScores.size());
        }
        String result = "";
        for (TotalSampleVo vo : hight) {
            result += vo.getName() + "、";
        }
        result = result.substring(0, result.length() - 1) + "学生德育发展水平检测得分较高；";
        for (TotalSampleVo vo : low) {
            result += vo.getName() + "、";
        }
        result = result.substring(0, result.length() - 1) + "学生得分较低";
        return result;
    }
}
